home *** CD-ROM | disk | FTP | other *** search
- /*
- * HelloApp.c
- * Copyright © 1991 Martin Minow. All rights reserved.
- * All use and non-commercial distribution permitted.
- */
- #include <CBartender.h>
- #include <CBureaucrat.h>
- #include <CDesktop.h>
- #include <CFWDesktop.h>
- #include <Commands.h>
- #include <TBUtilities.h>
- #include "HelloApp.h"
-
- extern CBartender *gBartender;
- extern CDesktop *gDesktop;
- extern CBureaucrat *gGopher;
-
- /*
- * IHelloApp -- the only thing this does is display the
- * logging window on the screen. It reacts to commands
- * by displaying the command number and sending them
- * onwards to the TCL CApplication method.
- */
- void
- HelloApp::IHelloApp(void)
- {
- CApplication::IApplication(8, 32768L, 4096L);
- itsTextWindow = NULL;
- MakeTextWindow(CmdMakeNoFloatHide); /* Normal window */
- itsTextWindow->SetTitle(
- (StringPtr) "\pHello (TCL) World!"
- );
- itsTextWindow->SetText(
- (StringPtr) "\pHello world!"
- );
- gGopher = this;
- }
-
- /*
- * Override MakeDesktop to allow creation of floating windows.
- */
- void
- HelloApp::MakeDesktop()
- {
- gDesktop = new(CFWDesktop);
- ((CFWDesktop *) gDesktop)->IFWDesktop(this);
- }
-
- /*
- * SetupMenus is called (by CApplication::IApplication).
- * It adds our application-specific menus to the menu bar.
- */
- void
- HelloApp::SetUpMenus()
- {
- Str255 work;
- short MENUid;
- short itemNo;
- MenuHandle macMenu;
-
- inherited::SetUpMenus();
- /*
- * Add some menu items to test UnknownCommand
- */
- gBartender->SetCmdText(
- cmdAbout,
- (StringPtr) "\pAbout Hello World"
- );
- gBartender->SetDimOption(MENU_Test, dimNONE);
- gBartender->SetDimOption(MENU_MakeTextWindow, dimNONE);
- AddResMenu(GetMHandle(MENUfont), 'FONT');
- gBartender->SetDimOption(MENUfont, dimNONE);
- gBartender->SetUnchecking(MENUfont, TRUE);
- /*
- * Build the TextWindow menu command on the fly.
- * You can also just add the command to a menu
- * in your resource file.
- */
- GetIndString(work, STRS_Toggle, kShowAuxWindow);
- gBartender->FindMenuItem(
- cmdToggleClip,
- &MENUid,
- &macMenu,
- &itemNo
- );
- if (macMenu != NULL && work[0] != 0) {
- gBartender->InsertMenuCmd(
- CmdToggleTextWindow,
- work,
- MENUid,
- itemNo
- );
- }
- }
-
- /*
- * UpdateMenus is called before showing a menu. Make sure
- * the Show/Hide text box command is enabled.
- */
- void
- HelloApp::UpdateMenus()
- {
- inherited::UpdateMenus();
- if (itsTextWindow != NULL)
- gBartender->EnableCmd(CmdToggleTextWindow);
- }
-
- /*
- * Execute a command. Only CmdToggleTextWindow does anything
- * useful.
- */
- void
- HelloApp::DoCommand(
- long theCommand
- )
- {
- switch (theCommand) {
- case CmdMakeNoFloatHide:
- case CmdMakeNoFloatShow:
- case CmdMakeIsFloatHide:
- case CmdMakeIsFloatShow:
- MakeTextWindow(theCommand); break;
- case CmdToggleTextWindow:
- itsTextWindow->Toggle(); break;
- case cmdAbout:
- if (itsTextWindow == NULL)
- MakeTextWindow(CmdMakeNoFloatHide);
- itsTextWindow->SetTitle(
- (StringPtr) "\pHello (TCL) World!"
- );
- itsTextWindow->SetText(
- (StringPtr) "\pHello world!"
- );
- itsTextWindow->SetText(
- (StringPtr) "\pCopyright © 1991"
- " Martin Minow,"
- " All rights reserved."
- );
- break;
- case cmdNew:
- if (itsTextWindow != NULL)
- itsTextWindow->SetText(
- (StringPtr) "\pNew selected");
- break;
- case cmdOpen:
- if (itsTextWindow != NULL)
- itsTextWindow->SetText(
- (StringPtr) "\pOpen selected");
- break;
- default:
- /*
- * I've found it useful to log commands
- * that aren't executed by my application
- * This catchs errors in setting the gopher
- * in a complicated web of sub-classes.
- */
- UnknownCommand(theCommand);
- inherited::DoCommand(theCommand);
- }
- }
-
- void
- HelloApp::MakeTextWindow(
- long theCommand
- )
- {
- Boolean isFloating;
- Boolean hideOnSuspend;
- Str255 titleText;
-
- if (itsTextWindow != NULL)
- itsTextWindow->Dispose();
- isFloating = (
- theCommand == CmdMakeIsFloatHide
- || theCommand == CmdMakeIsFloatShow
- );
- hideOnSuspend = (
- theCommand == CmdMakeNoFloatHide
- || theCommand == CmdMakeIsFloatHide
- );
- itsTextWindow = new(TextWindow);
- itsTextWindow->ITextWindow(
- this, /* The application */
- WIND_Note, /* WIND Resource id */
- isFloating, /* Not floating */
- hideOnSuspend, /* Don't hide */
- CmdToggleTextWindow, /* Show/Hide cmd */
- STRS_Toggle, /* Show/Hide STR# */
- (StringPtr) "\pgeneva", /* Font name */
- 9 /* Font size value */
- );
- gBartender->GetCmdText(theCommand, titleText);
- itsTextWindow->SetTitle(titleText);
- itsTextWindow->Show();
- }
-
-
- /*
- * Unrecognized commands (from the application) come here.
- * This method does nothing for TCL commands (cmdQuit,
- * cmdNull) that are normally handled by the TCL
- * CApplication method, and logs the command or menu
- * number for those the application should have handled.
- * If commands are logged, they may indicate menu items
- * are enabled incorrectly, the Gopher set incorrectly,
- * or a class failing to handle commands directed at it.
- */
- void
- HelloApp::UnknownCommand(
- long theCommand
- )
- {
- short theMenu;
- short theItem;
- Str255 work;
- Str255 number;
-
- theMenu = HiShort(-theCommand);
- theItem = LoShort(-theCommand);
- if (theCommand < 0 && theMenu == MENUapple)
- ; /* These are aways ok */
- else {
- switch (theCommand) {
- case cmdNull:
- case cmdQuit:
- case cmdToggleClip:
- break;
- default:
- if (theCommand >= 0) {
- CopyPString(
- (StringPtr) "\pUnknown command ",
- work
- );
- NumToString(theCommand, number);
- }
- else {
- CopyPString(
- (StringPtr) "\pUnknown menu ",
- work
- );
- NumToString(theMenu, number);
- ConcatPStrings(work, number);
- ConcatPStrings(work, (StringPtr) "\p.");
- NumToString(theItem, number);
- }
- ConcatPStrings(work, number);
- if (itsTextWindow != NULL)
- itsTextWindow->SetText(work);
- }
- }
- }
-
-
-